unit SyncNodeOptionUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OptionBaseUnit, StdCtrls, Buttons, ComCtrls, ExtCtrls, ADODB, DB;

type
  TfrmSyncNodeOption = class(TfrmOptionBase)
    Panel1: TPanel;
    lvComputer: TListView;
    Panel2: TPanel;
    lvSyncNode: TListView;
    Panel3: TPanel;
    Label4: TLabel;
    btnSet: TBitBtn;
    Splitter1: TSplitter;
    procedure btnSetClick(Sender: TObject);
  private
    { Private declarations }
    procedure LoadOption; override;
    procedure SaveOption; override;
  public
    { Public declarations }
  end;

var
  frmSyncNodeOption: TfrmSyncNodeOption;

implementation

uses FunctionUnit, MainUnit;

{$R *.dfm}

{ TfrmOptionBase1 }

procedure TfrmSyncNodeOption.LoadOption;
var
  Query: TADOQuery;
begin
  inherited;
  lvComputer.Clear;
  Query := TADOQuery.Create(Self);
  try
    OpenDataSet('SELECT * FROM Computer', Query, Database);
    while not Query.Eof do
    begin
      lvComputer.Items.Add.Caption := Query.FieldByName('ComputerName').AsString;
      Query.Next;
    end;
  finally
    Query.Free;
    Database.Close;
  end;

end;

procedure TfrmSyncNodeOption.SaveOption;
var
  Sql: string;
  Query: TADOQuery;
  i: Integer;
begin
  inherited;
//  lvSyncNode.Clear;
  Sql := 'DELETE  FROM SyncNode';
  ExecuteSql(Sql, Database);
  Sql := 'SELECT * FROM SyncNode';
  Query := TADOQuery.Create(Self);
  try
    OpenDataSet(Sql, Query, Database);
    for i := 0 to lvSyncNode.Items.Count - 1 do
    begin
      Query.Append;
      Query.FieldByName('ComputerName').Value := lvSyncNode.Items[i].Caption;
      Query.CheckBrowseMode;
    end;
  finally
    Query.Free;
    Database.Close;
  end;                      
end;

procedure TfrmSyncNodeOption.btnSetClick(Sender: TObject);
var
  i, j: Integer;
  bExist: Boolean;
begin
  inherited;
  for i := 0 to lvComputer.Items.Count - 1 do
  begin
    bExist := False;
    if lvComputer.Items[i].Selected then
    begin
      for j := 0 to lvSyncNode.Items.Count - 1 do
      begin
        if lvSyncNode.Items[j].Caption = lvComputer.Items[i].Caption then
        begin
          bExist := True;
          Break;
        end;
      end;
      if not bExist then
        lvSyncNode.Items.Add.Caption := lvComputer.Items[i].Caption;
    end;
  end;
end;

end.
